package com.ttl.springboot.utils;

import cn.dev33.satoken.stp.StpUtil;
import com.ttl.springboot.entity.User;
import com.ttl.springboot.mapper.UserMapper;

/**
 * 功能:Sa-Token工具类
 * 作者:江哥
 * 日期:2024/8/5 20:45
 */
public class SaUtils {

    /*
     * 获取当前的登录用户
     * */
    public static User getLoginUser() {
        Object loginId = StpUtil.getLoginId();
        if (loginId != null) {
            Integer userId = Integer.valueOf(loginId.toString());
            UserMapper userMapper = SpringUtils.getBean(UserMapper.class);
            return userMapper.selectById(userId);
        }
        return null;
    }
}
